<?php
class m_nilai extends CI_Model
{
	public $table = 'nilai';
	
	function get_data($where = null){
		$this->db->select('*');
		$this->db->from($this->table);
		if($where) $this->db->where($where);

		$query = $this->db->get();
		
		return $query->result();
	}
	
	function get_all_data($id){
		$this->db->select('*');
		$this->db->from($this->table);
		$this->db->join('ujian', 'nilai.uj_id = ujian.uj_id', 'inner');
		$this->db->join('siswa', 'siswa.sw_id = nilai.sw_id', 'inner');
		$this->db->join('mata_pelajaran', 'ujian.mp_id = mata_pelajaran.mp_id', 'inner');
		$this->db->where('nilai.sw_id', $id);

		$query = $this->db->get();
		
		return $query->result();
	}

	function get_report_data($id){
		$sql = "SELECT * FROM ( 
					SELECT a.* , b.nilai, b.sw_id, e.mp_name, e.mp_passgrade FROM ujian a 
					INNER JOIN nilai b ON a.uj_id = b.uj_id 
					INNER JOIN mata_pelajaran e ON a.mp_id = e.mp_id
				) a 
				INNER JOIN siswa b ON a.sw_id = b.sw_id
				INNER JOIN kelas c ON b.kl_id = c.kl_id
				WHERE b.kl_id IN (SELECT kl_id FROM kelas_ujian) AND b.sw_id = $id";
		$query = $this->db->query($sql);
		return $query->result();	
	}
	
	function insert($value){
		return $this->db->insert($this->table, $value);
	}
	
	function update($value, $where){
		return $this->db->update($this->table, $value, $where);
	}
	
	function delete($where){
		return $this->db->delete($this->table, $where);
	}
}
?>